# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DB_VER="5.3"
inherit autotools bash-completion-r1 db-use systemd flag-o-matic

DESCRIPTION="Dogecoin is a community-driven cryptocurrency that was inspired by a Shiba Inu meme."
HOMEPAGE="https://dogecoin.com"
SRC_URI="mirror://github/dogecoin/dogecoin/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64 ~arm ~arm64 ~mips ~ppc ~ppc64 ~x86 ~amd64-linux ~x86-linux"
IUSE="test +wallet zeromq"
RESTRICT="!test? ( test )"

RDEPEND="
	acct-group/dogecoin
	acct-user/dogecoin
	wallet? ( sys-libs/db:$(db_ver_to_slot "${DB_VER}")=[cxx] )
	zeromq? ( net-libs/zeromq:= )
"
BDEPEND="
	>=sys-devel/automake-1.13
	|| ( >=sys-devel/gcc-7[cxx] >=sys-devel/clang-5 )
"

DOCS=(
	doc/bips.md
	doc/files.md
	doc/REST-interface.md
	doc/reduce-memory.md
	doc/reduce-traffic.md
	doc/release-notes.md
	doc/tor.md
)

src_prepare() {
	default

	eautoreconf

	sed -i 's#/var/lib/dogecoin#/var/cache/dogecoin#g' contrib/init/dogecoind.service

	sed -i 's/TemporaryFileSystem/#TemporaryFileSystem/g' contrib/init/dogecoind.service
	sed -i 's/BindReadOnlyPaths/#BindReadOnlyPaths/g' contrib/init/dogecoind.service
	sed -i 's/BindReadOnlyPaths/#BindReadOnlyPaths/g' contrib/init/dogecoind.service
	sed -i 's/BindPaths/#BindPaths/g' contrib/init/dogecoind.service
}

src_configure() {
	local my_econf=(
		$(use_enable test tests)
		$(use_enable wallet)
		$(use_enable zeromq zmq)
	)
	econf "${my_econf[@]}"
}

src_install() {
	default

	insinto /etc/dogecoin
	newins "${FILESDIR}/dogecoin.conf" dogecoin.conf
	fowners dogecoin:dogecoin /etc/dogecoin/dogecoin.conf
	fperms 600 /etc/dogecoin/dogecoin.conf

	systemd_newunit "contrib/init/dogecoind.service" "dogecoind.service"

	mkdir -p "${D}/usr/lib/tmpfiles.d"
	echo "d /var/cache/dogecoin 0755 dogecoin dogecoin" >> "${D}/usr/lib/tmpfiles.d/dogecoin.conf"
	echo "d /var/log/dogecoin 0755 dogecoin dogecoin" >> "${D}/usr/lib/tmpfiles.d/dogecoin.conf"

	use zeromq && dodoc doc/zmq.md
}

pkg_extra_files() {
        echo "/var/cache/dogecoind/***"
}
